﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Jb.Common.Extensions;
using Jb.Domain;

namespace Jb.Web.Utility
{
    public static class SiteConfigReader
    {
        #region Constants
        public static class Constants
        {
            public const String COMPANY_URLS = "CompanyURLs";
            public const String CONTENT_URLS = "ContentURLs";
        }
        #endregion

        public static SiteConfiguration GetConfig(String key)
        {
            return ApplicationCache.SiteConfigurations.FirstOrDefault(P => P.ConfKey == key);
        }
        /// <summary>
        /// Gets the Maximum uploadable Resume file size in Mega Bytes (MB)
        /// Default value is 0.5 MB
        /// </summary>
        public static float MaxResumeFileSize
        {
            get
            {
                SiteConfiguration config = GetConfig("MaxResumeFileSize");
                if (config == null)
                    return 0.5F;
                return config.ConfValue.ToFloat();
            }
        }

        /// <summary>
        /// Determines how many coverletters a Job Seeker can Store
        /// Default value is 5
        /// </summary>
        public static int MaxCoverLetter
        {
            get
            {
                SiteConfiguration config = GetConfig("MaxCoverLetter");
                if (config == null)
                    return 5;
                return config.ConfValue.ToInt();
            }
        }

        /// <summary>
        /// Whether to automatically subscribe a newly registered company with a free subscription package
        /// </summary>
        public static bool AutoSubscribeToFreePackage
        {
            get
            {
                SiteConfiguration config = GetConfig("AutoSubscribeToFreePackage");
                if (config == null)
                    return false;
                return config.ConfValue.ToBoolean();
            }
        }

        /// <summary>
        /// Gets the Content type for a given file extension
        /// </summary>
        /// <param name="fileExtension"></param>
        /// <returns></returns>
        public static String GetContentType(String fileExtension)
        {
            String value = String.Empty;
            ApplicationCache.MimeTypes.TryGetValue(fileExtension, out value);
            return value;
        }

        /// <summary>
        /// Gets the salary range identifier used to populate salary range dropdown list.
        /// This should be used as annual starting salary range and then the increment constant. 
        /// Used in Salary range dropdownlist population
        /// Example: 15000:5000
        /// </summary>
        public static String SalaryRangeIdentifier
        {
            get
            {
                SiteConfiguration config = GetConfig("SalaryRangeIdentifier");
                if (config == null)
                    return "15000:5000";

                return config.ConfValue;
            }
        }
    }
}